package track;

import io.DbFuncs;

/**
 * This is the class for the track itself
 * 
 * @author Alex
 *
 */
public class Track {

	private int _id;
	private String _name = null;
	private Artist _artist = null;
	private Disc _disc = null;
	//The number of the track in the disc
	private int _orderNum = -1;
	private String _url = null;
	
	public Track(int id)
	{
		this._id = id;
	}
	
	public Track(int id, String name, Artist artist, Disc disc, int orderNum, String url)
	{
		this(id);
		this._name = name;
		this._artist = artist;
		this._disc = disc;
		this._orderNum = orderNum;
		this._url = url;
	}
	
	/**
	 * All the get functions
	 * 
	 * @return int
	 */
	public int getId()
	{
		return this._id;
	}
	/**
	 * @return String
	 */
	public String getName()
	{
		if(this._name == null)
			this._name = DbFuncs.getContentString("tracks", "name", "id", this._id);
		
		return this._name;
	}
	/**
	 * @return Artist
	 */
	public Artist getArtist()
	{
		if(this._artist == null)
			this._artist = new Artist(DbFuncs.getContentInt("tracks", "artist_id", "id", this._id));
		
		return this._artist;
	}
	/**
	 * @return Disc
	 */
	public Disc getDisc()
	{
		if(this._disc == null)
			this._disc = new Disc(DbFuncs.getContentInt("tracks", "disc_id", "id", this._id));
		
		return this._disc;
	}
	/**
	 * @return int
	 */
	public int getOrderNum()
	{
		if(this._orderNum == -1)
			this._orderNum = DbFuncs.getContentInt("tracks", "order_num", "id", this._id);
		
		return this._orderNum;
	}
	/**
	 * @return String
	 */
	public String getUrl()
	{
		if(this._url == null)
			this._url = DbFuncs.getContentString("tracks", "url", "id", this._id);
		
		return this._url;
	}
	
	public void set_name(String name) {
		_name = name;
	}

	/**
	 * Get the track as a string
	 */
	public String toString()
	{
		String artistName="", discName="";
		getArtist();
		getDisc();
		
		if(_artist != null)
			artistName = _artist.getName();
		if(_disc != null)
			discName = _disc.getName();
		
		return getName() + ": from " + artistName + " in the disc: " + discName;
	}
}
